using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UpgradePowerHarvester:Upgrade {

	public override void InitContext(WeaponSlot weapon,UpgradeInstance instance,UpgradeData boundData) {
		base.InitContext(weapon,instance,boundData);
		if(!extraData.ContainsKey("mobKilled")) extraData.Add("mobKilled",0);
		if(!extraData.ContainsKey("damageChange")) extraData.Add("damageChange",-30);
	}

	protected override void SubscribeEvents() {
		base.SubscribeEvents();
		Mob.Death+=Mob_Death;
	}
	public override void UnsubscribeEvents() {
		base.UnsubscribeEvents();
		Mob.Death-=Mob_Death;
	}

	private void Mob_Death(object _sender,DeathEventArgs e) {
		Mob sender = _sender as Mob;
		if(sender._maxHP<50) return;
		if(e.killerWeapon!=weapon.weapon) return;
		extraData["mobKilled"]=Mathf.Min((int)extraData["mobKilled"]+1,30);
		extraData["damageChange"]=-30+(int)extraData["mobKilled"]*2;
	}


	protected override void ProjectileFiringEventHandler(object _sender,ProjectileEventArgs e) {
		base.ProjectileFiringEventHandler(_sender,e);
		if(!IfReactProjectileEvent(_sender,e)) return;
		float damageX = 0.7f+Mathf.Min(0.02f*(int)extraData["mobKilled"],0.6f);
		e.stat.damage.AddMultAdd(damageX-1,0);
	}
}